package com.zxg.weixin.api.service.domain;

import java.io.StringReader;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

public class WeixinOrderQueryResponse {

	private String xml;
public WeixinOrderQueryResponse() {
	
}

	public WeixinOrderQueryResponse(String xml) {
	super();
	this.xml = xml;
	SAXReader reader = new SAXReader();
	StringReader sr = new StringReader(xml);
	
	try {
		Document doc  = reader.read(sr);
		Element root = doc.getRootElement();
		this.returnCode = root.element("return_code").getTextTrim();
		
		this.success = this.returnCode.equalsIgnoreCase("success");
		this.returnMsg=root.element("return_msg").getTextTrim();
		if(root.element("result_code")==null){
			success = false;
		}else{
			String result_code = root.element("result_code").getTextTrim();
			success  =  success && result_code.equalsIgnoreCase("success");
			 if(success)
				 this.paySuccess =root.element("trade_state").getTextTrim()!=null &&  root.element("trade_state").getTextTrim().equalsIgnoreCase("success");
		}
		
		
		
	} catch (DocumentException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
}

	private Boolean success;
	private String returnCode;
	private String returnMsg;
	private Boolean paySuccess;
	public String getXml() {
		return xml;
	}
	public void setXml(String xml) {
		this.xml = xml;
	}
	public Boolean getSuccess() {
		return success;
	}
	public void setSuccess(Boolean success) {
		this.success = success;
	}
	public String getReturnCode() {
		return returnCode;
	}
	public void setReturnCode(String returnCode) {
		this.returnCode = returnCode;
	}
	public String getReturnMsg() {
		return returnMsg;
	}
	public void setReturnMsg(String returnMsg) {
		this.returnMsg = returnMsg;
	}

	

	public Boolean getPaySuccess() {
		return paySuccess;
	}

	public void setPaySuccess(Boolean paySuccess) {
		this.paySuccess = paySuccess;
	}

	@Override
	public String toString() {
		return "WeixinPayResponse [success=" + success + ", returnCode="
				+ returnCode + ", returnMsg=" + returnMsg + "]";
	}
	
	
}
